package com.itwlj.controller.admin;

import com.itwlj.result.Result;
import com.itwlj.service.WorkspaceService;
import com.itwlj.vo.BusinessDataVO;
import com.itwlj.vo.OrderOverViewVO;
import com.itwlj.vo.OrderStats;
import com.itwlj.vo.UserStats;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工作台
 */
@RestController
@RequestMapping("/admin/workspace")
@Slf4j
@Api(tags = "工作台相关接口")
public class WorkSpaceController {

    @Autowired
    private WorkspaceService workspaceService;

    /**
     * 统计营业数据
     *
     * @return
     */
    @GetMapping("/businessData")
    @ApiOperation("统计营业数据")
    public Result<BusinessDataVO> getUserOverView() {
        log.info("统计营业数据");
        return Result.success(workspaceService.getBusinessData());
    }

    /**
     * 查询订单管理数据
     *
     * @return
     */
    @GetMapping("/orderOverView")
    @ApiOperation("查询订单管理数据")
    public Result<OrderOverViewVO> getOrderOverView() {
        log.info("查询订单管理数据");
        List<OrderOverViewVO> orderOverView = workspaceService.getOrderOverView(null, null);
        return Result.success(orderOverView.get(0));
    }

    /**
     * 查询用户统计数据
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/userStats")
    @ApiOperation("查询用户统计数据")
    public Result<List<UserStats>> getUserStats(String start, String end) {
        log.info("查询用户数据统计：日期{} TO {}", start, end);
        return Result.success(workspaceService.getUserStats(start, end));
    }

    /**
     * 查询订单统计数据
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/orderStats")
    @ApiOperation("查询订单统计数据")
    public Result<List<OrderStats>> getOrderStats(String start, String end) {
        log.info("查询订单数据统计：日期{} TO {}", start, end);
        return Result.success(workspaceService.getOrderStats(start, end));
    }

    /**
     * 导出用户统计数据
     *
     * @param response
     * @param start
     * @param end
     */
    @GetMapping("/export/userStats")
    @ApiOperation("导出用户统计数据")
    public void exportUserStats(HttpServletResponse response, String start, String end) {
        log.info("导出用户统计数据：日期{} TO {}", start, end);
        workspaceService.exportUserStats(response, start, end);
    }

    /**
     * 导出订单统计数据
     *
     * @param response
     * @param start
     * @param end
     */
    @GetMapping("/export/orderStats")
    @ApiOperation("导出订单统计数据")
    public void exportOrderStats(HttpServletResponse response, String start, String end) {
        log.info("导出订单统计数据：日期{} TO {}", start, end);
        workspaceService.exportOrderStats(response, start, end);
    }
}
